package com.tanhua.domain.vo;

import com.tanhua.domain.mongo.UserLocation;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * UserLocation的数据传输对象，可序列化
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserLocationDTO implements Serializable {
    /**主键值*/
    private String id;
    /**用户id*/
    private Long userId;
    /**经度*/
    private Double longitude;
    /**纬度*/
    private Double latitude;
    /**位置名称*/
    private String address;
    /**创建时间*/
    private Long created;
    /**更新时间*/
    private Long updated;
    /**最后更新时间*/
    private Long lastUpdated;

    /**
     * 把UserLocation对象转换成UserLocationDTO对象
     * @param userLocation 要转换的UserLocation对象
     * @return 转换后的UserLocationDTO对象
     */
    public static UserLocationDTO translate(UserLocation userLocation){
        UserLocationDTO dto = new UserLocationDTO();
        dto.setId(userLocation.getId().toHexString());
        dto.setUserId(userLocation.getUserId());
        dto.setLongitude(userLocation.getLocation().getX());
        dto.setLatitude(userLocation.getLocation().getY());
        dto.setAddress(userLocation.getAddress());
        dto.setCreated(userLocation.getCreated());
        dto.setUpdated(userLocation.getUpdated());
        dto.setLastUpdated(userLocation.getLastUpdated());
        return dto;
    }

    /**
     * 把UserLocation集合转换成UserLocationDTO集合
     * @param locationList 要转换的UserLocation集合
     * @return 转换后的UserLocationDTO集合
     */
    public static List<UserLocationDTO> translateList(List<UserLocation> locationList){
        List<UserLocationDTO> dtoList = new ArrayList<>(locationList.size());
        for (UserLocation userLocation : locationList) {
            dtoList.add(translate(userLocation));
        }
        return dtoList;
    }
}